package com.fr.base.core;

import com.fr.base.FRContext;
import com.fr.base.dav.Env;
import com.fr.util.Utils;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.io.File;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Hashtable;
import java.util.Locale;
import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.TransferHandler;

public class FRCoreContext
{
  private static Clipboard clipboard = null;
  private static byte[] bytes = null;
  public static final Hashtable TMAP = new Hashtable();

  public static Clipboard getClipboard(JComponent paramJComponent)
  {
    if (clipboard == null)
      try
      {
        Action localAction = TransferHandler.getCutAction();
        Method localMethod = Utils.getDeclaredMethod(localAction.getClass(), "getClipboard", new Class[] { JComponent.class });
        localMethod.setAccessible(true);
        return ((Clipboard)localMethod.invoke(localAction, new Object[] { paramJComponent }));
      }
      catch (Exception localException1)
      {
        localException1.printStackTrace();
        try
        {
          clipboard = paramJComponent.getToolkit().getSystemClipboard();
        }
        catch (Exception localException2)
        {
          localException2.printStackTrace();
          clipboard = new Clipboard("FR");
        }
      }
    return clipboard;
  }

  public static Class classForName(String paramString)
    throws ClassNotFoundException
  {
    Object localObject;
    try
    {
      return Class.forName(paramString);
    }
    catch (ClassNotFoundException localClassNotFoundException)
    {
      Env localEnv = FRContext.getCurrentEnv();
      if (localEnv == null)
        throw localClassNotFoundException;
      String str = localEnv.getPath();
      File localFile = new File(BaseCoreUtils.pathJoin(new String[] { str, "classes" }));
      try
      {
        localObject = new URLClassLoader(new URL[] { localFile.toURL() }, FRCoreContext.class.getClassLoader());
      }
      catch (MalformedURLException localMalformedURLException)
      {
        localObject = ClassLoader.getSystemClassLoader();
      }
    }
    return ((Class)Class.forName(paramString, true, (ClassLoader)localObject));
  }

  public static double convertChinaMillToInch(double paramDouble)
  {
    Locale localLocale = FRContext.getLocale();
    if (ComparatorUtils.equals(Locale.CHINA, localLocale))
      return BaseCoreUtils.convertMillimetersToInches(paramDouble);
    return paramDouble;
  }

  public static byte[] getBytes()
  {
    if (bytes == null)
    {
      InputStream localInputStream = null;
      Env localEnv = FRContext.getCurrentEnv();
      if (localEnv != null)
        try
        {
          localInputStream = localEnv.readResource("FineReport.lic");
        }
        catch (Exception localException)
        {
        }
      if (localInputStream != null)
        bytes = Utils.inputStream2Bytes(localInputStream);
      else
        bytes = new byte[0];
    }
    return bytes;
  }
}